﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Orderconsole;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.IO;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        System.Collections.Generic.List<Order> OrderList = new System.Collections.Generic.List<Order>();
        OrderService orderService = new OrderService();
        Order order1 = new Order("apple", "zxc",11);
        Order order2 = new Order("tomato",   "zxc",66);
        Order order3 = new Order("potato",  "lg",88);

        [TestInitialize]
        public void init()//订单序列初始化
        {
             OrderList.Add(order1);
            OrderList.Add(order2);
             OrderList.Add(order3);

        }

        [TestMethod]
        public void OrderAddTest()
            //添加订单测试
        {
            Order order4 = new Order("juice" , "lg",88);
             OrderList.Add(order4);
            Assert.AreEqual( OrderList.Count, 4);
        }


        [TestMethod]
        public void OrderDeleteTest()
            //删除订单测试
        {

            OrderList.Delete(3);
            Assert.AreEqual(OrderList.Count, 2);
        }

        [TestMethod]
        public void OrderAlterTest()
            //修改订单测试
        {
            OrderService orderService2 = new OrderService();
            orderService2 = orderService;
            OrderList.Alter(3);
            Assert.AreNotEqual(orderService, orderService2);
        }

        [TestMethod]
        public void ExportTest()
            //订单导出测试
        {
            string fileName = "order.xml";
            orderService.Export(fileName);
            Assert.IsTrue(File.Exists(fileName));
        }

        [TestMethod]
        public void ImportTest()//订单导入测试
        {
            OrderService orderService2 = new OrderService();
            orderService2.Import("order.xml");
            Assert.AreEqual(3,  OrderList.Count);
        }

    }
}

